package com.tjtt.gwm.dao.impl;

import java.util.Map;
import com.tjtt.gwm.dao.PipePointDao;
import com.tjtt.gwm.dao.SearchDao;
import com.tjtt.tdm.base.BaseHibernateDao;
import com.tjtt.tdm.base.PageResult;

public class PipePointDaoImpl extends BaseHibernateDao implements PipePointDao {
	
	public PageResult queryRangeSearch(Map filterMap){
		StringBuffer queryString = new StringBuffer();
		StringBuffer queryCountString = new StringBuffer();
		queryCountString.append(" select count(*) from ptem_search_range where 1=1 ");
		queryString.append("SELECT t.ID,t.QUERY_FIELD,t.QUERY_TABLE," +
				"t.CONDITION_FIELD_EN,t.CONDITION_FIELD_CN," +
				"t.CONDITION_TABLE,t.MAIN_FIELD,t.FOREIGN_FIELD,t.OWNER " +
				"FROM ptem_search_range t where 1=1 ");
		if (filterMap!= null && !filterMap.isEmpty()) {
			if(null != filterMap.get("strSearchName") &&! "".equals(filterMap.get("strSearchName"))){
				queryString.append("and t.OWNER = '" + filterMap.get("strSearchName") + "'  ");
				queryCountString.append("and OWNER = '" + filterMap.get("strSearchName") + "'  ");
			}
			String sidx = (String) filterMap.get("sidx");
			String sord = (String) filterMap.get("sord");
			queryString.append("order by " + sidx + " " + sord + " ");
		}
		return searchBySQL(queryCountString.toString(), queryString.toString(), filterMap);
	
	}
	public PageResult queryDateSearch(Map filterMap){
		StringBuffer queryString = new StringBuffer();
		StringBuffer queryCountString = new StringBuffer();
		queryCountString.append(" select count(*) from PTEM_SEARCH_DATE where 1=1 ");
		queryString.append("SELECT t.ID,t.QUERY_FIELD,t.QUERY_TABLE," +
				"t.CONNECT_TABLE,t.CONNECT_FIELD,t.CONNECT_FIELD_CON,"+
				"t.CONDITION_FIELD_EN,t.CONDITION_FIELD_CN," +
				"t.CONDITION_TABLE,t.MAIN_FIELD,t.FOREIGN_FIELD,t.OWNER " +
				"FROM PTEM_SEARCH_DATE t where 1=1 ");
		if (filterMap!= null && !filterMap.isEmpty()) {
			if(null != filterMap.get("strSearchName") &&! "".equals(filterMap.get("strSearchName"))){
				queryString.append("and t.OWNER = '" + filterMap.get("strSearchName") + "'  ");
				queryCountString.append("and OWNER = '" + filterMap.get("strSearchName") + "'  ");
			}
			String sidx = (String) filterMap.get("sidx");
			String sord = (String) filterMap.get("sord");
			queryString.append("order by " + sidx + " " + sord + " ");
		}
		return searchBySQL(queryCountString.toString(), queryString.toString(), filterMap);
	
	}
	//查询选择查询条件列表
	public PageResult querySelectSearch(Map filterMap){
		StringBuffer queryString = new StringBuffer();
		StringBuffer queryCountString = new StringBuffer();
		queryCountString.append(" select count(*) from PTEM_SEARCH_SELECT where 1=1 ");
		queryString.append("SELECT t.ID,t.QUERY_FIELD,t.QUERY_TABLE," +
				"t.CONNECT_TABLE,t.CONNECT_FIELD,t.CONNECT_FIELD_CON,"+
				"t.DICTIONARY_TABLE," +
				"t.CONDITION_FIELD_EN,t.CONDITION_FIELD_CN," +
				"t.CONDITION_TABLE,t.CONDITION_TABLE_CN,t.MAIN_FIELD,t.FOREIGN_FIELD,t.OWNER " +
				"FROM PTEM_SEARCH_SELECT t where 1=1 ");
		if (filterMap!= null && !filterMap.isEmpty()) {
			if(null != filterMap.get("strSearchName") &&! "".equals(filterMap.get("strSearchName"))){
				queryString.append("and t.OWNER = '" + filterMap.get("strSearchName") + "'  ");
				queryCountString.append("and OWNER = '" + filterMap.get("strSearchName") + "'  ");
			}
			String sidx = (String) filterMap.get("sidx");
			String sord = (String) filterMap.get("sord");
			queryString.append("order by " + sidx + " " + sord + " ");
		}
		return searchBySQL(queryCountString.toString(), queryString.toString(), filterMap);
	}
	//查询关键字查询条件列表
	public PageResult queryKeywordSearch(Map filterMap){
		StringBuffer queryString = new StringBuffer();
		StringBuffer queryCountString = new StringBuffer();
		queryCountString.append(" select count(*) from PTEM_SEARCH_KEYWORD where 1=1 ");
		queryString.append("SELECT t.ID,t.QUERY_FIELD,t.QUERY_TABLE," +
				"t.CONDITION_FIELD_EN,t.CONDITION_FIELD_CN," +
				"t.CONDITION_TABLE,t.MAIN_FIELD,t.FOREIGN_FIELD,t.OWNER " +
				"FROM PTEM_SEARCH_KEYWORD t where 1=1 ");
		if (filterMap!= null && !filterMap.isEmpty()) {
			if(null != filterMap.get("strSearchName") &&! "".equals(filterMap.get("strSearchName"))){
				queryString.append("and t.OWNER = '" + filterMap.get("strSearchName") + "'  ");
				queryCountString.append("and OWNER = '" + filterMap.get("strSearchName") + "'  ");
			}
			String sidx = (String) filterMap.get("sidx");
			String sord = (String) filterMap.get("sord");
			queryString.append("order by " + sidx + " " + sord + " ");
		}
		return searchBySQL(queryCountString.toString(), queryString.toString(), filterMap);
	
	}
	
	public PageResult queryAutoSearch(Map filterMap){
		StringBuffer queryString = new StringBuffer();
		StringBuffer queryCountString = new StringBuffer();
		
		queryCountString.append(" select count(*) from PTEM_SEARCH where 1=1 ");
		queryString.append("SELECT t.ID,t.SEARCH_NAME_CN,SEARCH_NAME_EN,t.CREATE_NAME,t.create_time FROM PTEM_SEARCH t where 1=1 ");
		if (filterMap!= null && !filterMap.isEmpty()) {
			if(null != filterMap.get("form_cn_name") &&! "".equals(filterMap.get("form_cn_name"))){
				queryString.append("and form_cn_name like '%" + filterMap.get("form_cn_name") + "%'  ");
				queryCountString.append("and form_cn_name like '%" + filterMap.get("form_cn_name") + "%'  ");
			}
			if(null != filterMap.get("form_en_name") &&! "".equals(filterMap.get("form_en_name"))){
				queryString.append("and form_en_name like upper('%" + filterMap.get("form_en_name") + "%')  ");
				queryCountString.append("and form_en_name like upper('%" + filterMap.get("form_en_name") + "%')  ");
			}
			if(null != filterMap.get("type") &&! "".equals(filterMap.get("type"))){
				queryString.append("and form_type = '" + filterMap.get("type") + "'  ");
				queryCountString.append("and form_type = '" + filterMap.get("type") + "'  ");
			}
			String sidx = (String) filterMap.get("sidx");
			String sord = (String) filterMap.get("sord");
			queryString.append("order by " + sidx + " " + sord + " ");
		}
		return searchBySQL(queryCountString.toString(), queryString.toString(), filterMap);
	
	}
	public PageResult queryPointPoleList(Map filterMap){
		StringBuffer countString = new StringBuffer();
		StringBuffer queryString = new StringBuffer();
		countString.append("select count(*) from ptem_point_pole t  where 1=1");
		queryString.append("select t.ID,t.POLENO,t.DEVICECODE," +
				"t.PROJECTNO,t.LOCATIONY,t.LOCATIONX,t.HEIGHT," +
				"t.LONGITUDE,t.LATITUDE,t.ELLIPSEH,t.LOCATIONDESCRIPTION," +
				"t.REMOTEEQUIPMENT,t.MANAGEUNIT,t.MANAGEDEPARTMENT,t.BUILDER," +
				"t.USETIME,t.POTENTIAL,t.PIPELINENO,t.PIPESECTIONNO,t.REMARK," +
				"t.ATTACHMENT,t.POLETYPE,t.PHOTO,t.SIGNEDUNIT,t.SIGNED from ptem_point_pole T  where 1=1 ");
		queryString.append(" and t.pipelineno = '"+filterMap.get("tzid")+"'");
		countString.append(" and t.pipelineno = '"+filterMap.get("tzid")+"'");
		queryString.append(" order by t.id desc");
		return searchBySQL(countString.toString(),queryString.toString(),filterMap);
	}
	public PageResult queryWeizhangzhanyaList(Map filterMap){
		StringBuffer countString = new StringBuffer();
		StringBuffer queryString = new StringBuffer();
		countString.append("select count(*) from ptem_violation t  where 1=1");
		queryString.append("select t.ID,t.VIOLATIONNO,t.VIOLATOR," +
				"t.OCCURTIME,t.VIOLATIONFORM,t.NATURE,t.ISSEDIMENTATION," +
				"t.LOCATIONDESCRIPTION,t.LOCATIONY,t.LOCATIONX,t.LOCATIONH," +
				"t.LONGITUDE,t.LATITUDE,t.LOCATIONELLIPSEH,t.PIPELINELENGTH," +
				"t.DISTANCE,t.STATE,t.SAFETYLEVEL,t.PHOTO,t.PIPELINENO," +
				"t.PIPESECTIONNO,t.REMARK,t.SIGNEDUNIT,t.SIGNED " +
				"from ptem_violation T  where 1=1 ");
		queryString.append(" and t.pipelineno = '"+filterMap.get("tzid")+"'");
		countString.append(" and t.pipelineno = '"+filterMap.get("tzid")+"'");
		queryString.append(" order by t.id desc");
		return searchBySQL(countString.toString(),queryString.toString(),filterMap);
	}
	public PageResult queryRiskS(Map filterMap){
		StringBuffer countString = new StringBuffer();
		StringBuffer queryString = new StringBuffer();
		countString.append("select count(*) from PTEM_RISK_S t  where 1=1");
		queryString.append("select t.ID,t.NO,t.EVALUATEITEM," +
				"t.EVALUATECONTENT,t.EVALUETESCORE,t.SCORE from PTEM_RISK_S T  where 1=1 ");
		queryString.append(" order by t.id asc");
		return searchBySQL(countString.toString(),queryString.toString(),filterMap);
	}
	public PageResult queryRiskC(Map filterMap){
		StringBuffer countString = new StringBuffer();
		StringBuffer queryString = new StringBuffer();
		countString.append("select count(*) from PTEM_RISK_C t  where 1=1");
		queryString.append("select t.ID,t.NO,t.EVALUATEITEM," +
				"t.EVALUATECONTENT,t.EVALUETESCORE,t.SCORE from PTEM_RISK_C T  where 1=1 ");
		queryString.append(" order by t.id asc");
		return searchBySQL(countString.toString(),queryString.toString(),filterMap);
	}
	public PageResult queryRiskWeight(Map filterMap){
		StringBuffer countString = new StringBuffer();
		StringBuffer queryString = new StringBuffer();
		countString.append("select count(*) from ptem_risk_weight t  where 1=1");
		queryString.append("select t.ID,t.fieldname,t.fieldvalue," +
				"t.fieldall from ptem_risk_weight T  where 1=1 ");
		queryString.append(" order by t.id asc");
		return searchBySQL(countString.toString(),queryString.toString(),filterMap);
	}
	public PageResult queryRiskEvaluate(Map filterMap){
		StringBuffer countString = new StringBuffer();
		StringBuffer queryString = new StringBuffer();
		countString.append("select count(*) from ptem_riskevaluate t  where 1=1");
		queryString.append("select t.ID,t.fieldname,t.fieldvalue," +
				"t.fieldunit from ptem_riskevaluate T  where 1=1 ");
		queryString.append(" order by t.id asc");
		return searchBySQL(countString.toString(),queryString.toString(),filterMap);
	}
	public PageResult queryRiskRes(Map filterMap){
		StringBuffer countString = new StringBuffer();
		StringBuffer queryString = new StringBuffer();
		countString.append("select count(*) from ptem_riske_result t  where 1=1");
		queryString.append("select t.ID,t.fieldname,t.fieldvalue," +
				"t.fieldres from ptem_riske_result T  where 1=1 ");
		queryString.append(" order by t.id asc");
		return searchBySQL(countString.toString(),queryString.toString(),filterMap);
	}
	public PageResult queryDaobojianceList(Map filterMap){
		StringBuffer countString = new StringBuffer();
		StringBuffer queryString = new StringBuffer();
		countString.append("select count(*) from ptem_guidedwaves_test t  where 1=1");
		queryString.append("select T.ID,T.TASKNO,T.PIPELINENO,T.PIPENO," +
				"T.LOCATIONNO,T.LOCATIONDESCRIPTION,T.TYPE,T.OUTERDIAMETER," +
				"T.WALLTHICKNESS,T.LOCATIONY,T.LOCATIONX," +
				"T.HEIGHT,T.LONGITUDE,T.LATITUDE,T.ELLIPSEH," +
				"T.TESTDATE,T.TESTUNIT,T.TESTER,T.DEVICENAMEMODEL," +
				"T.DEVICENO,T.PROBENO,T.TESTMETHOD,T.SERIALNO,T.TESTRESULT,T.ATTACHMENT " +
				"from ptem_guidedwaves_test T  where 1=1 ");
//		queryString.append("select t.ID,t.TASKNO,t.PIPELINENO," +
//				"t.PIPENO,t.LOCATIONNO,t.LOCATIONDESCRIPTION,t.TYPE," +
//				"t.OUTERDIAMETER,t.WALLTHICKNESS,t.LOCATIONY,t.LOCATIONX," +
//				"t.HEIGHT,t.LONGITUDE,t.LATITUDE,t.ELLIPSEH," +
//				"t.TESTDATE,t.TESTDATE,t.TESTER,t.DEVICENO," +
//				"t.PROBENO,t.TESTMETHOD,t.SERIALNO,t.TESTRESULT," +
//				"t.ATTACHMENT from ptem_guidedwaves_test T  where 1=1 ");
		queryString.append(" and t.pipelineno = '"+filterMap.get("tzid")+"'");
		countString.append(" and t.pipelineno = '"+filterMap.get("tzid")+"'");
		queryString.append(" order by t.id desc");
		return searchBySQL(countString.toString(),queryString.toString(),filterMap);
	}
}
